<?php

use yii\helpers\Url;


$this->title = '数据统计';
$this->registerJsFile('@web/assets/apache-echarts-5.2.2/dist/echarts.js', ['position' => \yii\web\View::POS_HEAD]);
?>

<style type="text/css">

</style>

<div id="balance" style="width:100%;margin:1em 0;">

    <div id="search" style="width:500px;margin-left:2em;background:#ffff87;border:#ccc 1px solid;padding:0.5em 1em;">
        <b style="color: red;">统计项目：</b>
        <select id="input_type" style="width:60px;height:26px;" onchange="window.search()">
            <option value="create" <?= $type == 'create' ? 'selected="selected"' : '' ?>>登记</option>
            <option value="order" <?= $type == 'order' ? 'selected="selected"' : '' ?>>预约</option>
            <option value="arrive" <?= $type == 'arrive' ? 'selected="selected"' : '' ?>>到诊</option>
        </select>
        <button onclick="window.select_month('previous')" type="button" class="btn btn-default btn-sm">上月</button>
        <input style="width:130px;" id="input_month" type="month" value="<?= $month ?>" onchange="window.search(this.value)" />
        <button onclick="window.select_month('after')" type="button" class="btn btn-default btn-sm">下月</button>
        <button onclick="window.select_month('now_month')" type="button" class="btn btn-danger btn-sm">回到当月</button>
    </div>

    <div id="tables" style="padding-top:1em;">
        <table class="layui-table">
            <tr style="background:#abcdef;">
                <td>姓名</td>
                <?php for ($index = 1; $index < 32; $index++) { ?>
                    <td><?= $index ?></td>
                <?php } ?>
            </tr>
            <?php foreach ($data as $user_id => $v) { ?>
                <tr>
                    <td><?= $users[$user_id] ?></td>
                    <?php for ($index = 1; $index < 32; $index++) {
                        $key = $month . '-' . $index; ?>
                        <td><?= $v[$key] ?></td>
                    <?php } ?>
                </tr>
            <?php } ?>
        </table>
    </div>

</div>

<script type="text/javascript">
    window.search = function(month_value = '') {
        if (month_value == '') {
            month_value = $('#month_value').val();
        }
        if (month_value == undefined) {
            month_value = "<?= $month ?>";
        }
        var input_type = $('#input_type').val();

        window.location.href = "<?= Url::toRoute('statistics/waiter') ?>&type=" + input_type + "&month=" + month_value;
    }

    window.select_month = function(value_string) {
        var input_type = $('#input_type').val();
        var month_value = '<?= date('Y-m') ?>';
        if (value_string == 'previous') {
            month_value = '<?= date('Y-m', strtotime(date($month) . ' - 1 month')) ?>';
        }
        if (value_string == 'after') {
            month_value = '<?= date('Y-m', strtotime(date($month) . ' + 1 month')) ?>';
        }
        window.search(month_value);
    }
</script>